import connection from '../app/database.js';
import {create} from "./user.js";

export async function registerUser(user){
    await create(user)
}

export async function loginUser({username, password}){
    const statement = `SELECT id, name username FROM users WHERE name = ? AND password = ?`
    const [result] =  await connection.execute(statement, [username, password])
    return result
}
export async function checkPermission(resourceType, id, userId){
    const statement = `SELECT * FROM ${resourceType} WHERE id = ? AND user_id = ?;`;
    const [result] = await connection.execute(statement, [id, userId]);
    return result.length
}